package com.example.phone.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;

public class PictureShowActivity extends Activity {
	ViewPager viewPager;
	ArrayList<View> list;
	ViewGroup main, viewGroup;
	ImageView imageView;
	ImageView[] imageViews;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		LayoutInflater inflater = getLayoutInflater();
		list = new ArrayList<View>();
		list.add(inflater.inflate(R.layout.item1, null));
		list.add(inflater.inflate(R.layout.item2, null));
		list.add(inflater.inflate(R.layout.item3, null));
		list.add(inflater.inflate(R.layout.item4, null));
		list.add(inflater.inflate(R.layout.item5, null));
		imageViews = new ImageView[list.size()];
		ViewGroup main = (ViewGroup) inflater.inflate(
				R.layout.picture_show_activity, null);

		ViewGroup group = (ViewGroup) main.findViewById(R.id.viewGroup);
		viewPager = (ViewPager) main.findViewById(R.id.viewPager);
		for (int i = 0; i < list.size(); i++) {
			imageView = new ImageView(PictureShowActivity.this);
			imageView.setLayoutParams(new LayoutParams(12, 12));
			// imageView.setPadding(10, 0, 10, 0);
			imageViews[i] = imageView;

			group.addView(imageView);
		}
		setContentView(main);
		viewPager.setAdapter(new MyAdapter());
	}

	class MyAdapter extends PagerAdapter {
		@Override
		public int getCount() {
			return Integer.MAX_VALUE;
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == arg1;
		}

		@Override
		public int getItemPosition(Object object) {
			// TODO Auto-generated method stub
			return super.getItemPosition(object);
		}

		@Override
		public void destroyItem(View arg0, int arg1, Object arg2) {
			// TODO Auto-generated method stub
			// ((ViewPager) arg0).removeView(list.get(arg1));
		}

		@Override
		public Object instantiateItem(View arg0, int arg1) {
			// TODO Auto-generated method stub
			try {
				((ViewPager) arg0).addView(list.get(arg1 % list.size()), 0);
			} catch (Exception e) {
				// TODO: handle exception
			}
			return list.get(arg1 % list.size());
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {
			// TODO Auto-generated method stub
		}

		@Override
		public Parcelable saveState() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
			// TODO Auto-generated method stub
		}

		@Override
		public void finishUpdate(View arg0) {
			// TODO Auto-generated method stub
		}
	}
}
